package biz.datalk.industrialland.admin.config;


import biz.datalk.industrialland.common.component.i18n.DatalkLocaleResolver;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;

import javax.annotation.Resource;
import java.util.Locale;

/**
 * 国际化配置
 *
 * @author tarofang@163.com
 * @date 2019-08-14
 */
@Configuration
public class I18NConfig {

    @Resource
    private MessageSource messageSource;

    /** 自定义验证器 */
    @Bean("customValidator")
    public Validator customValidator() {
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        validator.setValidationMessageSource(messageSource);
        return validator;
    }

    /**  */
    @Bean("localeResolver")
    public LocaleResolver localeResolver() {
        // SessionLocaleResolver localeResolver = new SessionLocaleResolver();
        DatalkLocaleResolver localeResolver = new DatalkLocaleResolver();
        localeResolver.setDefaultLocale(Locale.CHINESE);
        return localeResolver;
    }


}
